//
//  amqpcpp_streamer.hpp
//  Amqp_test
//
//  Created by HNXF on 2022/7/28.
//

#ifndef amqpcpp_streamer_hpp
#define amqpcpp_streamer_hpp

#include <boost/asio/io_service.hpp>
#include <memory>
#include <functional>
#include <thread>

namespace AMQP
{
    class Connection;
    class ConnectionHandler;
}  // namespace AMQP

class sync_channel;

using error_cb_signature = void(std::exception_ptr exception);
using on_error_cb = std::function<error_cb_signature>;

class amqpcpp_streamer {
public:
    amqpcpp_streamer();
    ~amqpcpp_streamer();
    void set_amqp_param( const std::string &addr,
                        const uint16_t port,
                        const std::string &vhost,
                        const std::string &user,
                        const std::string &pwd,
                        const on_error_cb cb);
    
    bool connect();
    
    void run();
    void stop();
    
    void publish(
        const std::string& topic,
        const std::string& partition_key,
        const std::string& event_type_name,
        const std::string& message);
    
//    void

private:
    std::string ip_address_;
    int port_;
    std::string vhost_;
    std::string username_;
    std::string password_;
    on_error_cb error_callback_;
    
    std::unique_ptr<AMQP::ConnectionHandler> connection_handler_;
    std::unique_ptr<AMQP::Connection> connection_;
    std::unique_ptr<sync_channel> channel_;
    
    std::thread io_service_thread_;
    std::unique_ptr<boost::asio::io_service> io_service_;
};

#endif /* amqpcpp_streamer_hpp */
